package com.cmc.cloud.cmclink.doc.controller.admin;

import cn.hutool.core.bean.BeanUtil;
import com.cmc.cloud.cmclink.doc.constants.UrlConstants;
import com.cmc.cloud.cmclink.doc.vo.bkgtarriffnovo.BkgTarriffNoCreateReqVO;
import com.cmc.cloud.cmclink.doc.vo.bkgtarriffnovo.BkgTarriffNoPageReqVO;
import com.cmc.cloud.cmclink.doc.vo.bkgtarriffnovo.BkgTarriffNoRespVO;
import com.cmc.cloud.cmclink.doc.vo.bkgtarriffnovo.BkgTarriffNoUpdateReqVO;
import com.cmes.framework.biz.advice.annotations.UseResponsePropertyAdvice;
import com.cmes.framework.common.pojo.CommonResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import java.util.*;


import com.cmes.framework.common.pojo.PageResult;

import com.cmc.cloud.cmclink.doc.entity.BkgTarriffNoDO;
import com.cmc.cloud.cmclink.doc.service.BkgTarriffNoService;


/**
 * {table.classComment}前端接口Controller
 * 
 * @author codegen
 */
@Tag(name = "管理后台 - 订舱公布价约号")
@RestController
@RequestMapping(UrlConstants.APPLICATION_URL+"/tarriffNo")
@Validated
public class BkgTarriffNoController {

    @Resource
    private BkgTarriffNoService bkgTarriffNoService;

    @Operation(summary = "创建订舱公布价约号")
    @PostMapping("/create")
    public CommonResult<Void> createBkgTarriffNo(@Valid @RequestBody BkgTarriffNoCreateReqVO createReqVO) {
        bkgTarriffNoService.createBkgTarriffNo(createReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "更新订舱公布价约号")
    @PostMapping("/update")
    public CommonResult<Void> updateBkgTarriffNo(@Valid @RequestBody BkgTarriffNoUpdateReqVO updateReqVO) {
        bkgTarriffNoService.updateBkgTarriffNo(updateReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "删除订舱公布价约号")
    @Parameter(name = "id", description = "编号", required = true)
    @PostMapping("/delete/{id}")
    public CommonResult<Void> deleteBkgTarriffNo(@PathVariable("id") Long id) {
        bkgTarriffNoService.deleteBkgTarriffNo(id);
        return CommonResult.success();
    }

    @Operation(summary = "获得订舱公布价约号")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @GetMapping("/getById/{id}")
    public CommonResult<BkgTarriffNoRespVO> getBkgTarriffNo(@PathVariable("id") Long id) {
        BkgTarriffNoDO bkgTarriffNo = bkgTarriffNoService.getBkgTarriffNo(id);
        return CommonResult.success(BeanUtil.copyProperties(bkgTarriffNo, BkgTarriffNoRespVO.class));
    }

    @Operation(summary = "通过订舱人代码 获得订舱公布价约号")
    @Parameter(name = "bkpCode", description = "订舱人代码", required = true, example = "CSM1938138026941980672")
    @GetMapping("/getByBkpCode/{bkpCode}")
    public CommonResult<BkgTarriffNoRespVO> getByBkpCode(@PathVariable("bkpCode") String bkpCode) {
        BkgTarriffNoDO bkgTarriffNo = bkgTarriffNoService.getByBkpCode(bkpCode);
        return CommonResult.success(BeanUtil.copyProperties(bkgTarriffNo, BkgTarriffNoRespVO.class));
    }

    @Operation(summary = "获得订舱公布价约号列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @GetMapping("/listAll")
    public CommonResult<List<BkgTarriffNoRespVO>> getBkgTarriffNoList(@RequestParam("ids") Collection<Long> ids) {
        List<BkgTarriffNoDO> list = bkgTarriffNoService.getBkgTarriffNoList(ids);
        return CommonResult.success(BeanUtil.copyToList(list, BkgTarriffNoRespVO.class));
    }

    @Operation(summary = "获得订舱公布价约号分页")
    @UseResponsePropertyAdvice
    @PostMapping("/getPage")
    public CommonResult<PageResult<BkgTarriffNoRespVO>> getBkgTarriffNoPage(@Valid @RequestBody BkgTarriffNoPageReqVO pageVO) {
        PageResult<BkgTarriffNoRespVO> pageResult = bkgTarriffNoService.getBkgTarriffNoPage(pageVO);
        return CommonResult.success(pageResult);
    }
}
